define(function(require, exports, module) {
	var RemoteCache=require('resources/js/component/RemoteCache.js');
	require('resources/js/component/TreeDropDown.js');
	
	var url={
		appId:'/appId.jhtml',
	};
	
	var ResPublishEditor=function(data,$div,config){
		this.resPublish=data;
		this.$div=$div;
		
		this.baseUrl=config.baseUrl;
		this.readOnly=config.readOnly===undefined?false:config.readOnly;
		
		this.init();
	};
	
	ResPublishEditor.remoteCache=new RemoteCache();
	
	ResPublishEditor.prototype={
		init:function(){
			ResPublishEditor.remoteCache.get('appId',this.getUrl('appId'));
			this.render();
			this.bind();
			this.sync();
			this.readOnlyRender();
		},
		getUrl:function(key){
			return this.baseUrl+url[key];
		},
		get:function(key){
			return ResPublishEditor.remoteCache.get(key)
		},
		render:function(){
			//关联应用下拉框  //TODO-lisn 应用管理
			this.appTree=new TreeDropDown({
				treeData:this.get('appId'),
				$input:$('input[name=appName]',this.$div),
				$inputValue:$('input[name=appId]',this.$div),
				readOnly:this.readOnly,
				desc:'请选择'	//空值描述的文字
			});
		},
		readOnlyRender:function(){
			if(!this.readOnly)
				return ;
			
			$('input,textarea',this.$div).attr('readonly','readonly');
			$('select',this.$div).attr('disabled','disabled');
		},
		bind:function(){
			
		},
		sync:function(){
			this.appTree.setValue(this.resPublish.appId);
		},
		fillData:function(resPublish){
			this.resPublish=resPublish;
			this.sync();
		},
		getError:function(){
			var error=[];
			if(!this.resPublish.title)
				error.push("申请标题必填");
			if(!this.resPublish.appId)
				error.push("关联应用必填");
			return error;
		}
	};
	
	return ResPublishEditor;
	
});